<!DOCTYPE html>
<html class="iframe-h">

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>网站后台管理模版</title>
    <link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css"/>
</head>

<body>
<div class="wrap-container clearfix">
    <div class="column-content-detail">
        <div class="layui-form" id="table-list">
            <div id="table_thead_view"></div>
            <div>
                <div id="my_page" style="text-align:center"></div>
            </div>
        </div>
    </div>
</div>
<script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/admin/js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery-1.7.2.min.js"></script>
<script type="text/html" id="table_thead_temp">
    <table class="layui-table" lay-even lay-skin="nob">
        <thead>
        <tr>
            <th>序号</th>
            <th>标题</th>
            <th>紧急程度</th>
            <th>申请时间</th>
            <th>审批类型</th>
            <th>审批</th>

        </tr>
        </thead>
        <tbody>
        {{# layui.each(d.data, function(index, item){ }}
        <tr>
            <td>{{index+1}}</td>
            <td>{{item.title}}</td>
            <td>{{item.urgent}}</td>
            <td>{{item.creationtime}}</td>
            <td>{{item.flowTitle}}</td>
            <td>
                <button type="button" class="layui-btn layui-btn-mini layui-btn-normal"
                        onclick="flow('{{item.processId}}',1,'{{item.serviceId}}','{{item.flowId}}')">
                    通过
                </button>
                <button type="button" class="layui-btn layui-btn-mini layui-btn-danger"
                        onclick="flow('{{item.processId}}',0,'{{item.serviceId}}','{{item.flowId}}')">
                    拒绝
                </button>
            </td>
        </tr>
        {{# }); }}
        </tbody>
    </table>

</script>
<script>
    $(function () {
        show();
    })

    function show() {
        layui.use(['form', 'laytpl', 'laypage'], function () {
            var laytpl = layui.laytpl;
            var load_index = layer.load(0, {shade: [0.2, '#393D49']});
            $.ajax(ip + 'flow/getFlowToMe', {
                dataType: 'json',
                type: 'post'
            }).done(function (data) {
                layer.close(load_index);
                if (data.code == '0') {
                    var table_thead_temp = document.getElementById('table_thead_temp').innerHTML;
                    laytpl(table_thead_temp).render(data, function (html) {
                        document.getElementById('table_thead_view').innerHTML = html;
                    });
                } else {
                    layer.alert(data.message, {
                        icon: 5,
                        title: "提示"
                    });
                }
            })
        })
    }

    function flow(processId, status, serviceId, flowId) {
        if (status == 1) {
            confirm_message = '通过该申请';
        } else if (status == 0) {
            confirm_message = '拒绝该申请';
        }
        layer.confirm(confirm_message, {
                btn: ['确定', '取消'],
                offset: '100px',
                yes: function (index, layero) {
                    $.ajax(ip + 'flow/approval', {
                        dataType: 'json',
                        type: 'post',
                        data: {
                            'processId': processId,
                            'status': status,
                            'serviceId': serviceId,
                            'flowId': flowId
                        }
                    }).done(function (data) {
                        layer.close(index)
                        if (data.code == '0') {
                            show();
                        } else {
                            layer.alert(data.message, {
                                icon: 5,
                                title: "提示"
                            });
                        }
                    })
                }, btn2: function (index, layero) {
                    layer.close(index)
                },
                cancel: function (index, layero) {
                    layer.close(index)
                }
            }
        );


    }

</script>
</body>

</html>